<%@ page import="com.xju.entity.User" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>电子商务系统 - 主页</title>
    <link rel="stylesheet" type="text/css" href="static/css/style.css">
</head>
<body>
<header>
    <h1>欢迎来到电子商务系统</h1>
    <nav>
        <ul>
            <li><a href="index.jsp">首页</a></li>
            <li><a href="ProductListServlet">产品列表</a></li>
            <%
                User user = (User) session.getAttribute("user");
                if (user != null) {
            %>
            <li><a href="/CartServlet">购物车</a></li>

            <%
                }
            %>
            <%
                if (user == null) {
            %>
            <li><a href="login.jsp">登录</a></li>
            <li><a href="register.jsp">注册</a></li>
            <%
            } else {
            %>
            <li>
                <div class="user-profile">
                    <img src="static/images/user.png" alt="User Profile" class="profile-img">
                    <div class="user-menu">
                        <a href="myinfo.jsp">我的信息</a>
                        <a href="logout.jsp">退出登录</a>
                        <a href="orders.jsp">我的订单</a>
                    </div>
                </div>
            </li>
            <%
                }
            %>
        </ul>
    </nav>
</header>
<main>
    <section class="hero">
        <h2>精选商品</h2>
        <div class="product-list">
            <div class="product-item">
                <img src="static/images/product1.jpg" alt="Product 1">
                <h3>商品1</h3>
                <p>价格: $3999.0</p>
                <button onclick="addToCart(1)">加入购物车</button>
            </div>
            <div class="product-item">
                <img src="static/images/product2.jpg" alt="Product 2">
                <h3>商品2</h3>
                <p>价格: $299.0</p>
                <button onclick="addToCart(2)">加入购物车</button>
            </div>
            <!-- 更多商品项 -->
        </div>
    </section>
</main>
<footer>
    <p>&copy; 2023 电子商务系统. All rights reserved.</p>
</footer>
<script src="static/js/main.js"></script>
<%
    String loginMessage = (String) session.getAttribute("loginMessage");
    if (loginMessage != null) {
%>
<script>
    alert('<%= loginMessage %>');
</script>
<%
    session.removeAttribute("loginMessage");
%>
<%
    }
%>
</body>
</html>
